PT-2368 - refactor all tools cli#1096
Conversation
This change intorduces refactoring of all tools to work with new config implementation.
svetasmirnova
left a comment
There was a problem hiding this comment.
Please finish the merge of 3.x and resolve conflicts: pt-k8s-debug-collector tests fail.
svetasmirnova
left a comment
There was a problem hiding this comment.
pt-mongodb-summary test also fails. Looks like another conflict issue:
=== RUN TestGetMongosInfo
main_test.go:296:
Error Trace: /home/sveta/src/percona/percona-toolkit/src/go/pt-mongodb-summary/main_test.go:296
Error: Should not be: 0
Test: TestGetMongosInfo
--- FAIL: TestGetMongosInfo (0.00s)
This is not right. |
| Encrypt bool `name:"collect" negatable:"" default:"true"` | ||
| Sanitize bool `name:"sanitize" negatable:"" default:"true"` | ||
| SanitizeHostnames bool `name:"encrypt" negatable:"" default:"true"` | ||
| SanitizeQueries bool `name:"sanitize-hostnames" negatable:"" default:"true"` | ||
| Collect bool `name:"sanitize-queries" negatable:"" default:"true"` |
There was a problem hiding this comment.
There is a mess between field names and tags.
| for _, incDir := range c.IncludeDirs { | ||
| incDir = expandHomeDir(incDir) | ||
| } |
There was a problem hiding this comment.
You just throwing away modified incDir here, c.IncludeDirs stays unmodified.
| if _, err = os.Stat(*opts.TempDir); os.IsNotExist(err) { | ||
| log.Infof("Creating temporary directory: %s", *opts.TempDir) | ||
| if err = os.Mkdir(*opts.TempDir, os.ModePerm); err != nil { | ||
| log.Fatalf("Cannot create temporary dirextory %q: %s", *opts.TempDir, err) | ||
| } | ||
| } |
There was a problem hiding this comment.
Shouldn't we still create temp dir?
| if !*opts.NoRemoveTempFiles { | ||
| if err = removeTempFiles(*opts.TempDir, !*opts.NoEncrypt); err != nil { | ||
| log.Fatal(err) | ||
| } |
There was a problem hiding this comment.
It seems that this functionality was missed. Temporary files never deleted and --remove-temp-files flag does nothing.
| toolname, Version, Build, GoVersion, Commit, | ||
| ), | ||
| }, | ||
| ) //TODO fix help |
There was a problem hiding this comment.
What's wrong with the help?
| ) | ||
|
|
||
| var ( | ||
| CLI = &cliOptions{} |
There was a problem hiding this comment.
I would suggest to
| CLI = &cliOptions{} | |
| CLI cliOptions |
And later refer it as &CLI
| decryptCmd = "decrypt" | ||
| encryptCmd = "encrypt" | ||
| collectCmd = "collect" | ||
| sanitizeCmd = "sanitize" |
There was a problem hiding this comment.
Some of these are unused
| if args.Version { | ||
| return | ||
| } |
There was a problem hiding this comment.
It seems that this is redundant. Kong exits automatically for version flag.
| ``--skip-pod-summary`` | ||
| Skip the collection of pod-specific summary data. | ||
|
|
||
| ``--skip-pod-summary`` | ||
|
|
||
| Skip pod summary collection. | ||
|
|
Co-authored-by: Artem Gavrilov <artem.gavrilov@percona.com>
Co-authored-by: Sveta Smirnova <svetasmirnova@users.noreply.github.com>
Co-authored-by: Sveta Smirnova <svetasmirnova@users.noreply.github.com>
Summary
This PR migrates CLI/config handling to the new Kong-based configuration layer across all affected Go tools.
The goal is to standardize flag parsing, config-file behavior, password prompts, and version/version-check flow using shared config primitives.
Changes
kong.VersionFlaginlib/config/commonFlags.go.config.Setup(...)in:pt-mongodb-index-checkpt-mongodb-query-digestpt-mongodb-summarypt-pg-summarypt-secure-collectgetopt/kingpin) with Kong struct tags and hooks (AfterApply, commandRunmethods).config.VersionCheckFlag+versioncheck.CheckUpdates(...).config.StdinRequestStringfor DB/encryption passwords.pt-secure-collectsubcommands (collect,encrypt,decrypt,sanitize) to command structs with explicit validation and runtime handlers.Notes
This is primarily a CLI/config refactor; no intended functional changes in business logic.
Main expected impact is behavior consistency across tools (flags, defaults, help/version output, password prompts).
The contributed code is licensed under GPL v2.0
Contributor Licence Agreement (CLA) is signed
util/update-modules has been ran
Documentation updated
Test suite update